<template>
	<view class="container">
		<v-tabs v-model="current" :tabs="tabs" @change="changeTab" :fixed="true"></v-tabs>
		<view v-if="isfetch">
			<view class="flex f-column" v-if="orderList.length > 0">
				<view class="goods-item flex f-column" v-for="(item, index) in orderList" :key="index" @click="item.visit == '1' ? '' : toDetail(item)">
					<view class="flex f-align f-justifyB mt20" v-if="orderState != '已预约'">
						<text class="font28 gray333">订单编号：{{item.orderNumber}}</text>
						<text class="font28" style="color: #BB1E32;">{{orderState}}</text>
					</view>
					<view class="flex f-align item-top">
						<image :src="item.orderDetails[0].goodsUrl" class="item-img"></image>
						<view class="flex f-column ml20">
							<text class="font36 gray333 text-overflow" style="width: 500rpx;">{{item.orderDetails[0].goodName}}</text>
							<view class="flex wrap mt10">
								<view class="top-item">清洗</view>
								<view class="top-item" v-for="(a,b) in toArr(item.orderDetails[0].projectName)" :key="b">{{a}}</view>
							</view>
							<!-- font22 -->
							<view v-if="orderState == '已预约' && item.visit == '1'">
								<text class="font22 gray333 text-overflow" style="width: 500rpx;">上门时间：{{item.visitDate}}</text>
							</view>
							<view v-else></view>
							<view v-if="orderState == '已预约'">
								<text class="font22 gray333 text-overflow" style="width: 500rpx;">服务地址：{{item.province}} {{item.city}} {{item.area}} {{item.visitAddress}}</text>
							</view> 
							<view v-else></view>
							
							<text class="font28 gray777 mt20" v-if="orderState == '已预约'">{{item.gzbhAddress}}</text>
							<view class="flex f-align f-justifyB mt20" v-else>
								<text class="font36 gray333">数量 x {{item.goodsNumber}}</text>
								<view class="code-btn" v-if="orderState == '待取件'">{{item.visit == '1' ? '待取件' :'查看开箱码'}}</view>
								<text class="font36 gray333 bold" v-else>￥{{item.actualPayment}}</text>
							</view>
						</view>
					</view>
					<view class="flex f-align f-justifyB item-bottom" v-if="orderState == '已预约'">
						<view class="font36 gray333" style="letter-spacing: 10rpx;">
							共<text class="red">{{item.goodsNumber}}</text>单
						</view>
						<view class="code-btn">{{item.visit == '1' ? '待取件' :'查看开箱码'}}</view>
					</view>
				</view>
				<uni-load-more ref="loadMore" :status="loadStatus"></uni-load-more>
			</view>
			<view class="flex f-column f-align" v-else>
				<text class="font36 gray999 bold mt50">暂无订单</text>
			</view>
		</view>
	</view>
</template>

<script>
	import vTabs from '@/components/v-tabs/v-tabs.vue'
	import loadMore from '@/components/uni-load-more/uni-load-more.vue'
	export default {
		data() {
			return {
				current: 0,
				tabs: ['已预约', '服务中', '待取件', '交易完成'],
				page: 1,
				loadStatus: 'more',
				isfetch: false,
				orderList: [],
				orderState: '',
				
				typeId: '',
				
			}
		},
		components: {
			vTabs,
			loadMore
		},
		onLoad(option) {
			this.orderState = option.orderState
			this.current = option.tabs
		},
		onShow() {
			this.page = 1
			this.loadStatus = 'more'
			this.getOrderList()
		},
		onPullDownRefresh() {
			this.page = 1
			this.loadStatus = 'more'
			this.getOrderList()
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 1000)
		},
		onReachBottom() {
			if (this.loadStatus != 'noMore') {
				this.loadStatus = 'loading'
				this.page += 1
				this.getOrderList()
			}
		},
		methods: {
			toArr(str) {
				if (!str) {
					return []
				} else {
					return str.split(',')
				}
			},
			closePopup() {
				
			},
			toDetail(item) {
				this.$api.toPage('./orderDetail?orderId=' + item.id + '&type=3' + '&orderState=' + this.orderState)
			},
			changeTab(status) {
				this.isfetch = false
				this.orderState = status
				this.page = 1
				this.loadStatus = 'more'
				this.getOrderList()
			},
			getOrderList() {
				this.$http.ajax({
					url: '/Order/list',
					params: {
						userId: uni.getStorageSync('userInfo').id,
						orderState: this.orderState,
						page: this.page,
						limit: 10
					}
				}).then((res) => {
					console.log(JSON.stringify(res));
					this.isfetch = true
					if (res.code == 0) {
						if (res.data.length < 10) {
							this.loadStatus = 'noMore'
						}
						if (this.page > 1) {
							this.orderList = this.orderList.concat(res.data)
						} else {
							this.orderList = res.data
						}
					} else {
						this.orderList = []
						this.loadStatus = 'noMore'
						this.$api.msg(res.msg)
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	
	.tip-box {
		width: 750rpx;
		background: #ffffff;
		padding: 34rpx 20rpx 68rpx;
		border-radius: 30rpx 30rpx 0 0;
		
		.box-t {
			padding: 0 35rpx;
			
			.title {
				position: relative;
			}
			.title::before {
				width: 6rpx;
				height: 32rpx;
				background: #3063d9;
				position: absolute;
				left: -16rpx;
				top: 6rpx;
				content: '';
			}
			.f-justifyB {
				margin-bottom: 30rpx;
			}
		}
		.btn {
			width: 710rpx;
			height: 100rpx;
			background: #3063d9;
			border-radius: 20rpx;
			margin-top: 10rpx;
		}
	}
	
	
	.goods-item {
		width: 750rpx;
		background: #ffffff;
		margin-top: 30rpx;
		position: relative;
		padding: 0 32rpx;
		
		.item-top {
			padding: 28rpx 0;
			
			.top-item {
				width: 82rpx;
				height: 32rpx;
				background: #4082FF;
				border-radius: 18rpx;
				font-size: 24rpx;
				line-height: 32rpx;
				color: #FFFFFF;
				text-align: center;
				margin: 10rpx 10rpx 0 0;
			}
		}

		.item-img {
			width: 160rpx;
			height: 160rpx;
		}
		
		.item-bottom {
			padding: 30rpx 0;
			border-top: 2rpx solid #AAAAAA;
		}
		
		.code-btn {
			width: 180rpx;
			height: 60rpx;
			background: #4082FF;
			border-radius: 32rpx;
			font-size: 28rpx;
			line-height: 60rpx;
			color: #FFFFFF;
			text-align: center;
		}
	}

	.container {
		padding: 0;
	}
</style>
